import sys
import pandas as pd
from PySide2.QtWidgets import QApplication, QWidget, QTableView, QHeaderView, QHBoxLayout
from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt

class ResultDataModel(QAbstractTableModel):
    def __init__(self, data=pd.DataFrame()):
        QAbstractTableModel.__init__(self)
        self.__data = data
        self.__hHeader = self.__data.columns.tolist()
        self.__vHeader = self.__data.index.tolist()

    def rowCount(self, parent=QModelIndex()):
        return self.__data.shape[0]

    def columnCount(self, parent=QModelIndex()):
        return self.__data.shape[1]

    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None
        if role == Qt.TextAlignmentRole:
            return Qt.AlignCenter
        if role == Qt.DisplayRole:
            return str(self.__data.iloc[index.row()][index.column()])
        return None

    def headerData(self, section, orientation, role):
        if role != Qt.DisplayRole:
            return None
        if orientation == Qt.Horizontal:
            return self.__hHeader[section]
        elif orientation == Qt.Vertical:
            return self.__vHeader[section]


class Test(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.setMinimumSize(800, 500)
        df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]], index=['A', 'B'], columns=['One', 'Two', 'Three', 'Four'])
        print(df)
        self.tableModel = ResultDataModel(df)
        self.tableView = QTableView()
        self.tableView.setModel(self.tableModel)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableView.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)

        layout = QHBoxLayout()
        layout.addWidget(self.tableView)
        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    widget = Test()
    widget.resize(1000, 800)
    widget.show()
    sys.exit(app.exec_())